/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function ShowLoadding(){
    $("#loaddingAjax").show();
    $("#loaddingAjax .proccessbar").stop(true).width(0).css({
        backgroundColor:"green",
        bottom:1
    })
    .animate({
        width:'30%'
    },200)
    .animate({
        width:'50%',
        backgroundColor:"blue"
    },500)
    .animate({
        width:'75%',
        backgroundColor:"orange"
    },2000)
    .animate({
        width:'95%',
        backgroundColor:"red"
    },5000);
}
function HideLoadding(){
    $("#loaddingAjax .proccessbar").stop(true)
    .animate({
        width:'100%',
        backgroundColor:"red"
    },500,function(){
        $("#loaddingAjax").hide();
    });
        
        
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
function CloseConfirmDialogMessage(confirm){
    if(typeof(confirm)=="object"){
        confirm.dialog( "close" );
    }else{
        $( "#confirm-dialog-message" ).dialog( "close" );
    }
}
function OpenConfirmDialogMessage(confirm){
    if(typeof(confirm)=="object"){
        confirm.dialog( "open" );
    }else if(typeof(confirm)=="string"){
        $( "#confirm-dialog-message" ).dialog( "open" );
    }
}
function ShowConfirmDialogMessage( confirm ,title, callback ){
    var obj;
    if(typeof(confirm)=="object"){
        obj=confirm;
    }else if(typeof(confirm)=="string"){
        obj=$( "#confirm-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( confirm );
    }
        
        
    //$( "#confirm-dialog-message" ).attr("title", title );
    //$( "#confirm-dialog-message" ).dialog( 'open' );
        
    obj.dialog({
        resizable   : false,
        minwidth      :240,
        width      :'auto',
        modal       : true,
        bgiframe: true,
        //hide        : "explode",
        title: "<img style='position:absolute;top:7px;left:8px' src='"+baseurl+"syslib/jquery-ui-1.9.2/themes/base/images/action_check.png'/><font style='padding-left:20px;'>"+(title==undefined?"Xác nhận !":title)+"</font>",
        buttons: {
            Ok: function() {
                //$( this ).dialog( "close" );
                if (callback && typeof(callback) === "function") { 
                    try{
                        callback();           
                    }catch(e){

                    }
                }
            }
            ,
            Cancel: function() {
                $( this ).dialog( "close" );
            }
        }
    });              
                 
}
function ShowErrorDialogMessage( error_message , callback ){
    var obj;
    if(typeof(error_message)=="object"){
        obj=error_message;
    }else if(typeof(error_message)=="string"){
        obj=$( "#error-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( error_message );
    }
        
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        resizable   : false,
        minwidth      :240,
        width      :'auto',
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        //                Ok: function() {
        //                    $( this ).dialog( "close" );
        //                }
        },
        title: "<img style='position:absolute;top:7px;left:8px' src='"+baseurl+"syslib/jquery-ui-1.9.2/themes/base/images/dialog_error.png'/><font style='padding-left:20px;color:red'>Lỗi !</font>",
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });              
            
         
}
function ShowNoticeDialogMessage( notice_message ,title, callback ){
    var obj;
    if(typeof(notice_message)=="object"){
        obj=notice_message;
    }else if(typeof(notice_message)=="string"){
        obj=$( "#notice-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( notice_message );
    }
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        minwidth      :'320px',
        resizable: false,
        width      :'auto',
        title: "<img style='position:absolute;top:7px;left:8px' src='"+baseurl+"syslib/jquery-ui-1.9.2/themes/base/images/dialog_warning.png'/><font style='padding-left:20px;'>"+(title==undefined?"Thông báo !":title)+"</font>",
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        },
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });             
}
function ShowDialogMessage( notice_message ,title, callback ){
    var obj;
    if(typeof(notice_message)=="object"){
        obj=notice_message;
    }else if(typeof(notice_message)=="string"){
        obj=$( "#notice-dialog-message" );
        //obj.dialog( "destroy" );
        obj.html( notice_message );
    }
    obj.dialog({
        modal: true,
        //autoOpen            : false,
        minwidth      :'320px',
        resizable: false,
        width      :'auto',
        title: ( title == undefined ? "Thông báo !" : title ),
        closeOnEscape       : false,
        //hide                : "explode",
        buttons: {
        },
        close: function(event, ui) { 
            if (callback && typeof(callback) === "function") { 
                try{
                    callback();           
                }catch(e){

                }
            } 
        }
    });             
}
function untip(){
    $("#tipMessage").stop().hide();
}
function stoptip(){
    $("#tipMessage").stop().show();
}
function tipMessage(msg,auto){
        
    if($("#tipMessage").length==0 || typeof($("#tipMessage")) == 'undefined' || $("#tipMessage") == null || $("#tipMessage") == undefined){
        $('body').append('<div onmouseover="stoptip()" id="tipMessage" class="tip-green" style="visibility: inherit; left: 360px; top: 36px; opacity: 1;position: fixed;z-index:2002">\
                <div class="tip-inner tip-bg-image tipcontent">Loadding...</div>\
                <div class="tip-arrow tip-arrow-bottom" style="visibility: inherit;position: absolute"></div>\
                <div class="tip-close" onclick="untip()"></div>\
            </div>');
    }
    $("#tipMessage .tipcontent").html(msg);
    if(auto==undefined){
        $("#tipMessage").stop().fadeIn().delay(5000).fadeOut();
    }else{
        $("#tipMessage").stop().fadeIn();
    }
}


function myAjax(surl,odata,callback){
    isrunning=true;
    ShowLoadding();
    jQuery.ajax({
        type:"POST", 
        data:odata, 
        dataType:"text", 
        url:surl, 
        success: function (data){
            isrunning=false;
            HideLoadding(); 
            try{
                    
                var result=JSON.parse(data);
                    
                if (callback && typeof(callback) === "function") { 
                    try{
                        callback(result);  
                    }catch(e){
                        console.log("Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                        ShowErrorDialogMessage(e.message);
                    }
                } 
            }catch(e){
                console.log("JSON Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                ShowErrorDialogMessage("<pre>JSON Error:"+e.message+"\nContent:\n"+data+"</pre>");
            }
        },
        error: function (xhr, ajaxOptions, thrownError){
            console.log("Status:"+xhr.status+"\nThrownError:"+thrownError+"\nURL:"+surl+"\n↵ Error");
            isrunning=false;
            HideLoadding();
            ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
            
        }
    });
}
function htmlAjax(surl,sdata,obj,callback){
    isrunning=true;
    ShowLoadding();
    jQuery.ajax({
        type:"POST", 
        data:sdata, 
        dataType:"text", 
        url:surl, 
        success: function (data){
            isrunning=false;
            HideLoadding(); 
            try{
                if(typeof(obj)=="object"){

                }else if(typeof($(obj))=="object"){
                    obj=$(obj);
                }else{
                    console.log("Sorry. Element not found.\n↵ Error");
                    tipMessage("Sorry. Element not found.");
                    return;
                }
                obj.html(data);
                if (callback && typeof(callback) === "function") {  
                    callback();  
                }
            }catch(e){
                console.log("Error:"+e.message+"\nContent:"+data+"\n↵ Error");
                ShowErrorDialogMessage("<pre>Error:"+e.message+"\nContent:"+data+"</pre>");
            }
        },
        error: function (xhr, ajaxOptions, thrownError){
            console.log("Status:"+xhr.status+"\nThrownError:"+thrownError+"\nURL:"+surl+"\n↵ Error");
            isrunning=false;
            HideLoadding(); 
            ShowErrorDialogMessage("Sorry. Your request could not be completed.<br/> Please check your input data.");
        }
    });
}
function BrowseServer( _objid )
{
    try{
        window.KCFinder = {};
        window.KCFinder.callBack = function(url) { 
            window.KCFinder = null;
            $('#'+_objid).val(url);
            console.log(url);
        };
        window.open( baseurl+'syslib/kcfinder/browse.php?lang=vi', 'kcfinder_textbox',
            'status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=0, width=700, height=500'
            );
    }catch(e){
        console.log("JSON Error:"+e.message+"\n↵ Error");
        ShowErrorDialogMessage(e.message);
    }
}
function hideparent(t){
    $(t).parent().hide(500);
}
function tab(){
    
}
function chkb(chk){
    $(chk).toggleClass("cked");
}
function rdbck(rdb){
    if($(rdb).attr("group"))
        $(".radio.cked[group='"+$(rdb).attr("group")+"']").removeClass("cked");
    else
        $(".radio.cked").removeClass("cked");
    $(rdb).addClass("cked");
            
}
function s_m_b(obj){
    $(obj).parent().find(".more-box").show();
}
